<template>
	<view class="page">
		<!-- 蓝色背景区域 -->
		<view class="blue-background"></view>
		
		<!-- 主内容容器 -->
		<view class="main-content">
			<!-- 支付成功通知列表 -->
			<view class="notification-list" v-if="!loading && notificationList.length > 0">
				<view class="notification-item" v-for="(item, index) in notificationList" :key="item.id">
					<view class="notification-header">
						<text class="notification-title">{{ item.title }}</text>
						<text class="notification-time">{{ formatTime(item.time) }}</text>
					</view>
					<view class="notification-content">
						<text class="payment-amount">{{ item.content }}</text>
					</view>
				</view>
			</view>
			
			<!-- 加载状态 -->
			<view class="loading-container" v-if="loading">
				<text class="loading-text">加载中...</text>
			</view>
			
			<!-- 空状态 -->
			<view class="empty-container" v-if="!loading && notificationList.length === 0">
				<text class="empty-text">暂无消息</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				notificationList: [],
				loading: false,
				uid: 1 // 用户ID，暂时设置为1
			}
		},
		onLoad() {
			console.log('页面加载，当前uid:', this.uid);
			this.getMessageList();
		},
		methods: {
			// 获取消息列表
			async getMessageList() {
				this.loading = true;
				try {
					const response = await uni.request({
						url: 'http://localhost:8080/user/message/list',
						method: 'GET',
						data: {
							uid: this.uid
						},
						 header: {
						        'Authorization': "eyJhbGciOiJIUzUxMiJ9.eyJ1c2VyX2lkIjoxLCJ1c2VyX2tleSI6ImE2MDNmZDhmLTNiZmQtNDRkNC1iYTFhLTBjNGQwZDIxOGRhNiIsInVzZXJuYW1lIjoiYWRtaW4ifQ.Q9FCl0XmirOM_QUxmV0rx17uAy0lNDTGHESpZ3-AGZq4Kthpjb1aN5vdJPu8O68iQDAI8FWf4b2nxKFsfBhYZQ", // 常用格式：Bearer + 空格 + token
						        // 或根据后端要求的字段名，例如：
						        // 'token': token
						      }
					});
					
					if (response.data && response.data.code === 200) {
						this.notificationList = response.data.rows || [];
					} else {
						uni.showToast({
							title: response.data?.msg || '获取消息失败',
							icon: 'none'
						});
					}
				} catch (error) {
					console.error('获取消息列表失败:', error);
					uni.showToast({
						title: '网络错误，请重试',
						icon: 'none'
					});
				} finally {
					this.loading = false;
				}
			},
			
			// 格式化时间显示
			formatTime(timeStr) {
				if (!timeStr) return '';
				// 将 "2025-09-16" 格式转换为 "2025.09.16" 格式
				return timeStr.replace(/-/g, '.');
			}
		}
	}
</script>

<style>
	.page {
		background-color: #f5f6fa;
		min-height: 100vh;
		position: relative;
	}
	
	/* 蓝色背景区域 */
	.blue-background {
		position: absolute;
		top: 0;
		left: 0;
		width: 100%;
		height: 300rpx;
		background: linear-gradient(120deg, #3385fd 0%, #3385fd 100%);
	}
	
	/* 主内容容器 */
	.main-content {
		position: absolute;
		top: 1rpx;
		left: 2%;
		/* transform: translateX(-50%); */
		width: 96%;
		/* max-width: 750rpx; */
		z-index: 10;
		padding: 20rpx 0;
	}
	
	/* 通知列表 */
	.notification-list {
		background: #ffffff;
		border-radius: 20rpx;
		/* box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.1); */
		overflow: hidden;
	}
	
	/* 通知项 */
	.notification-item {
		padding: 30rpx;
		position: relative;
	}
	
	.notification-item:not(:last-child)::after {
		content: '';
		position: absolute;
		bottom: 0;
		left: 50%;
		transform: translateX(-50%);
		width: 94%;
		height: 3rpx;
		background-color: #f0f0f0;
	}
	
	/* 通知头部 */
	.notification-header {
		display: flex;
		justify-content: space-between;
		align-items: center;
		margin-bottom: 15rpx;
	}
	
	.notification-title {
		font-size: 28rpx;
		color: #333333;
		font-weight: 500;
	}
	
	.notification-time {
		font-size: 25rpx;
		color: #999999;
	}
	
	/* 通知内容 */
	.notification-content {
		margin-top: 10rpx;
	}
	
	.payment-amount {
		font-size: 25rpx;
		color: #333333;
		line-height: 1.4;
	}
	
	/* 加载状态 */
	.loading-container {
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 100rpx 0;
	}
	
	.loading-text {
		font-size: 28rpx;
		color: #999999;
	}
	
	/* 空状态 */
	.empty-container {
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 100rpx 0;
	}
	
	.empty-text {
		font-size: 28rpx;
		color: #999999;
	}
</style>